﻿<%@ Page Title="" Language="C#" MasterPageFile="~/shop/view.master" AutoEventWireup="true"
    CodeBehind="buy.aspx.cs" Inherits="ZF.WS.shop.buy" %>

<%@ Register Src="../UserControls/shop/header.ascx" TagName="header" TagPrefix="uc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <link href="../css/validator.css" rel="stylesheet" type="text/css" />

    <script src="../js/formValidatorRegex.js" type="text/javascript"></script>

    <script src="../js/formValidator.js" type="text/javascript"></script>

    <script src="/js/jqPlugins/areaJson.js" type="text/javascript"></script>

    <script src="/js/jqPlugins/json2select.min.js" type="text/javascript"></script>

    <script type="text/javascript" src="/js/jqPlugins/onlypressnum.js"></script>

</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <div class="location mb10_">
        您现在的位置：<a href="/"><%=SiteInfo.Instance.SystemConfig.SiteName %></a> >> <a href="/shop/list.aspx">
            商品列表</a> >> <a href="/shop/info.aspx?id=<%=MercId %>">商品购买</a>
    </div>
    <uc1:header ID="header1" runat="server" />

    <script>

        $(function() {

            $.formValidator.initConfig({ formid: document.forms[0].id, onerror: function(msg) { alert(msg) } });


            $(".tbPhone").formValidator({ tipid: "tbPhoneTip", onshow: " ", onfocus: " ", oncorrect: " ", onempty: "" })
    .regexValidator({ regexp: "mobile", datatype: "enum", onerror: "手机格式错误" });
            //          $(".tbTel").formValidator({ tipid: "tbTelTip", onshow: "格式：区号-电话号码-分机。如：020-83643131",
            //          onfocus: "格式：区号-电话号码-分机。如：020-83643131", oncorrect: "格式：区号-电话号码-分机。如：020-83643131", onempty: ""
            //      }).regexValidator({ regexp: "mobile", datatype: "enum", onerror: "固定电话格式错误" });

            $(".tbConsignee").formValidator({ tipid: "tbConsigneeTip", onshow: " ", onfocus: " ", oncorrect: " " })
    .inputValidator({ min: 1, onerror: "请输入收货人姓名" });


            $("#area").json2select(areaJson, ["广东省", "广州市", "天河区"], "area", 2);

        });
    
    
    </script>

    <script language='javascript' type="text/javascript">
        function refreshValidateCodeImage(ValidateCodeImageControl) {

            var url = ValidateCodeImageControl.src;
            if (url.indexOf("?code=") > -1) {
                url = url.split("?")[0];
            }
            ValidateCodeImageControl.src = url + '?code=' + randomNum(10);
        }
        function randomNum(n) {
            var rnd = '';
            for (var i = 0; i < n; i++)
                rnd += Math.floor(Math.random() * 10);
            return rnd;

        }
        $(function() {
            $(".vcodeimg")[0].click();

        });
    </script>

    <div class="editContainer mt10_">
        <table class=" w100_ edit   edit1   ">
            <tbody>
                <tr>
                    <th colspan="4">
                        <div class="c">
                            确认收货地址
                        </div>
                    </th>
                </tr>
                <tr>
                    <td class="ll">
                        <div class="c">
                            <span class="xh_">*</span>您的手机号码：
                        </div>
                    </td>
                    <td class="lr">
                        <div class="c">
                            <zf:TextBox runat="server" ID="tbPhone" class="stxt"></zf:TextBox>
                            <span class="zx_" id="tbPhoneTip"></span>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td class="ll">
                        <div class="c">
                            <span class="xh_"></span>固定电话号码：
                        </div>
                    </td>
                    <td class="lr">
                        <div class="c">
                            <zf:TextBox runat="server" ID="tbTel" class="txt"></zf:TextBox>
                            <span class="zx_" id="tbTelTip"></span>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td class="ll">
                        <div class="c">
                            <span class="xh_">*</span>收货人姓名：
                        </div>
                    </td>
                    <td class="lr">
                        <div class="c">
                            <zf:TextBox runat="server" ID="tbConsignee" class="sstxt"></zf:TextBox>
                            <span class="zx_" id="tbConsigneeTip"></span>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td class="ll">
                        <div class="c">
                            <span class="xh_">*</span>收货区域：
                        </div>
                    </td>
                    <td class="lr">
                        <div class="c">
                            <span id="area"></span>
                            <zf:TextBox runat="server" ID="tbArea" class="dn_"></zf:TextBox>
                            <zf:TextBox runat="server" ID="tbArea1" class="dn_"></zf:TextBox>
                            <script>
                                $(function() {
                                    $(document.forms[0]).submit(function() {
                                        var area = "";
                                        if ($("select[@name='area0']").length > 0) {
                                            area += $("select[@name='area0']")[0].value;
                                            $(".tbArea1").val($("select[@name='area0']")[0].value);
                                        } else {
                                            alert("请选择省份"); return false;
                                        }
                                        if ($("select[@name='area1']").length > 0) {
                                            area += $("select[@name='area1']")[0].value;
                                        }
                                        if ($("select[@name='area2']").length > 0) {
                                            area += $("select[@name='area2']")[0].value;
                                        }
                                        $(".tbArea").val(area);

                                    });
                                    $("select[@name='area0']").change(function() {
                                        area0_change(this);

                                    });

                                    
                                });
                                function area0_change(obj) {
                                    var selArea = obj.value
                                    if (selArea != null) {//选中地区名称
                                        $(freightTemplate).each(function() {
                                            if (this.Key == selArea) {
                                                var r = $(".freightSet :radio[value=2]");
                                                if (r.length > 0) {
                                                    $(r[0].parentNode).find("label").html(String.format("快递:{0}元", this.Text));
                                                }
                                                return false;
                                            }
                                        });
                                    }
                                    settj();

                                }
                            </script>

                            &nbsp;&nbsp;&nbsp;&nbsp;邮 编：
                            <zf:TextBox runat="server" ID="tbZipcode" class="sstxt"></zf:TextBox>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td class="ll">
                        <div class="c">
                            <span class="xh_">*</span>街道地址：
                        </div>
                    </td>
                    <td class="lr">
                        <div class="c">
                            <zf:TextBox runat="server" ID="tbAddress" class="mstxt" Style="height: 40px"></zf:TextBox>
                            <br />
                            <span class="zx_">请填写你收货的详细地址</span>
                        </div>
                    </td>
                </tr>
            </tbody>
            <tbody>
                <tr>
                    <th colspan="2">
                        <div class="c">
                            订单设置
                        </div>
                    </th>
                </tr>
                <tr>
                    <td class="ll">
                        <div class="c">
                            <span class="xh_">*</span>数量：
                        </div>
                    </td>
                    <td class="lr tdPrice">
                        <div class="c">
                            <zf:TextBox runat="server" ID="tbQuantity" Text="1" class="sstxt"></zf:TextBox>(<%=Merc.Unit %>)<br />
                        </div>
                    </td>
                </tr>
                <tr>
                    <td class="ll">
                        <div class="c">
                            <span class="xh_">*</span>价格：
                        </div>
                    </td>
                    <td class="lr tdPriceType">
                        <div class="c">
                            <input type="radio" checked="checked" name="rPriceType" id="rPriceType1" value="1" /><label
                                for="rPriceType1">普通价格:<%=Merc.CPrice %>元/<%=Merc.Unit %>
                            </label><zf:TextBox runat="server" ID="tbPriceType" class="dn_"  Text="1"></zf:TextBox>
                            <%--<br />
                            <input type="radio" name="rPriceType" id="rPriceType2" value="2" /><label for="rPriceType2">会员价格:(<%=Merc.MPrice %>元+<%=Merc.Integral %>积分)/<%=Merc.Unit %></label>
                            
                            <br />
                            &nbsp;<span class="zx_">您当前的可用积分有：<span class="spanCIntegral"><%=CIntegral %></span>积分</span>
                            <a href="http://www.zf.com/Person/space/Recharge.aspx" style="color: #f00; text-decoration: underline;
                                font-size: 14px;">积分充值</a>--%>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td class="ll">
                        <div class="c">
                            <span class="xh_">*</span>货运方式：
                        </div>
                    </td>
                    <td class="lr">
                        <div class="c freightSet  " style="text-align:left">
                            <zf:RadioButtonList ID="rblFreight" runat="server" style="float:left">
                            </zf:RadioButtonList>
                           
                            <span class="<%=Freight!=null?"":"dn_" %>"><a href="javascript:_openFT(<%=Merc.FreightId %>)">
                                查看全国各省快递费用</a> </span>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td class="ll">
                        <div class="c">
                            <span class="xh_"></span>统计：
                        </div>
                    </td>
                    <td class="lr">
                        <div class="c tdPrice">
                            <span class="ppt">单价：</span><span class="pdj"><%=Merc.CPrice %>元</span> <span>数量：</span><span
                                class="pdec">1</span><%=Merc.Unit %>
                            <span>运费：</span><span class="pft"></span> <span>合计：</span><span class="phj fc2 f14_ fw_"><%=Merc.CPrice %>元</span>

                            <script>
                            
                                var freightTemplate=$.evalJSON('<%=Freight==null?"null":Freight.Json %>');
                                var freightTypes = $.evalJSON('<%=Merc.FreightSet %>');
                                var setFreightType = null;
                                
                                function settj(pt, p, fp) {

                                    var ft = getFreightType();
                                    if (ft != null) {
                                        $(".pft").html(String.format("{0}元", ft.Price));
                                    } else {
                                        return;
                                    }
                                      

                                    var pt = "" + $(".tdPriceType :checked")[0].value;
                                    var dec = parseInt($(".tbQuantity").val());
                                    $(".pdec").html(dec);

                                    if (pt == "1") {
                                        $(".ppt").html("单价：");
                                        $(".pdj").html(String.format("{0}元", "<%=Merc.CPrice %>"));

                                        var phjp = parseFloat("<%=Merc.CPrice %>") * dec + ft.Price;

                                        $(".phj").html(String.format("{0}元", phjp));

                                    } else if (pt == "2") {
                                        $(".ppt").html("会员单价：");
                                        $(".pdj").html(String.format("{0}元+{1}积分", "<%=Merc.MPrice %>", "<%=Merc.Integral %>"));
                                        var phjp = parseFloat("<%=Merc.MPrice %>") * dec + ft.Price;
                                        var phjf = parseInt("<%=Merc.Integral %>") * dec
                                        $(".phj").html(String.format("{0}元+{1}积分", phjp, phjf));
                                    }
                                }
                                function getFreightType() {
                                    var type = null;
                                    var value = $(".freightSet :checked")[0].value
                                    $(freightTypes).each(function() {
                                        if (this.Type + "" == value) {
                                            type = this;
                                            return false;
                                        }
                                    });
                                    if (type != null) {
                                        setFreightType = type;
                                        if (setFreightType.Type == 2) {
                                            var selArea = $("select[@name='area0']")[0].value
                                            if (selArea != null) {//选中地区名称
                                                $(freightTemplate).each(function() {
                                                if (this.Key == selArea) {
                                                        setFreightType.Price = this.Text;
                                                        return false;
                                                    }
                                                });
                                            }

                                        }
                                        return setFreightType;
                                    } else {
                                        alert("运送方式错误");
                                        return null;
                                    }
                                }



                                $(function() {
                                    $(".tdPriceType :radio").click(function() {
                                        $(".tbPriceType").val(this.value);
                                        settj();
                                    });
                                    $(".tbQuantity").change(function() {
                                        settj();
                                    });
                                    $(".freightSet input").click(function() {
                                        settj();
                                    });
                                    if ($(".freightSet input[@value=2]").length > 0)
                                        $(".freightSet input[@value=2]")[0].click();
                                    area0_change($("select[@name='area0']")[0]);
                                });
                            </script>

                            <script>


                                $(".freightSet input").click(function() {
                                    var type = null;
                                    var value = this.value;
                                    $(freightTypes).each(function() {
                                        if (this.Type + "" == value) {
                                            type = this;
                                            return false;
                                        }
                                    });
                                    if (type != null) {
                                        setFreightType = type;
                                        resetPrice();
                                    } else {
                                        alert("运送方式错误");
                                    }

                                });
                                function resetPrice() {
                                    var price = parseFloat($(".tdPrice .ap").attr("price"));
                                    var discount = parseFloat($(".tdPrice .ap").attr("discount"));
                                    var quantity = parseInt($(".tbQuantity").val());
                                    var xj = (Math.round(parseFloat((price * quantity) * discount) * 10) / 100); //小计
                                    var integral = parseFloat($(".tbIntegral").val()) / 10;
                                    xj = Math.round((xj - integral) * 100) / 100;
                                    $(".tdPrice .ap").html(xj + "元");
                                    if (setFreightType != null)
                                        $(".tdPrice .zp").html(xj + setFreightType.Price + "元");
                                    else
                                        alert("请选择运送方式");
                                }
                                
                                
                                
                               
                                
                            </script>

                            <%--<script>
                            var maxIntegral=<%=Merc.Integral %>;
                            var memberIntegral=<%=CIntegral %>;
                        </script>
                            <script>
                               
                                $(function() {

                                    $(".tbQuantity").change(function() {
                                        if (this.value == "")
                                            this.value = 1;
                                        resetPrice();
                                    }).onlypressnum();

                                    $(".tbIntegral").change(function() {
                                        if (this.value == "")
                                            this.value = 0;
                                        if (parseInt(this.value) > memberIntegral) {
                                            alert("您的可用积分只有" + memberIntegral + "个积分");
                                            if (maxIntegral < memberIntegral)
                                                this.value = maxIntegral;
                                            else
                                                this.value = memberIntegral;
                                        } else if (parseInt(this.value) > maxIntegral) {
                                            alert("该商品最高可使用" + maxIntegral + "积分进行抵价");
                                            this.value = maxIntegral;
                                        }
                                        $(".spanCIntegral").html(memberIntegral - parseInt(this.value));
                                        resetPrice();
                                    }).onlypressnum();
                                });
                            </script>

                            --%>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td class="ll">
                        <div class="c">
                            <span class="xh_">*</span>支付方式：
                        </div>
                    </td>
                    <td class="lr">
                        <div class="c paySet" style="text-align:left">
                            <zf:RadioButtonList ID="rblPayType" RepeatDirection="Horizontal" runat="server">
                                <asp:ListItem Text="支付宝支付" Value="1" Selected="True"></asp:ListItem>
                                <asp:ListItem Text="货到付款" Value="2"></asp:ListItem>
                                <asp:ListItem Text="银行转帐" Value="3"></asp:ListItem>
                            </zf:RadioButtonList>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td class="ll">
                        <div class="c">
                            <span class="xh_"></span>购物留言：
                            <br />
                            (100字以内)
                        </div>
                    </td>
                    <td class="lr">
                        <div class="c">
                            <zf:TextBox runat="server" ID="tbPubInfo" class="mstxt" Style="width: 400px; height: 50px"></zf:TextBox>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td class="ll">
                        <div class="c">
                            <span class="xh_">*</span>验证码：
                        </div>
                    </td>
                    <td class="lr">
                        <div class="c">
                            <zf:TextBox runat="server" ID="tbVCode" class="stxt"></zf:TextBox>
                            <img src="/ValidatePage.aspx" style="cursor: pointer" class='vcodeimg' onclick="refreshValidateCodeImage(this);" />
                        </div>
                    </td>
                </tr>
            </tbody>
            <tbody>
                <tr class="b">
                    <td colspan="4">
                        <div>
                            <zf:Button ID="btAdd" OnClick="BuySubmit" class="linkbtn addSubmit" runat="server"
                                Text=" 确认无误，支付 "></zf:Button>
                            <input type="button" class="linkbtn" value=" 取 消 " />
                        </div>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</asp:Content>
